<?php
/**
* @file $Id: Warehouse.php 456 2007-04-23 05:39:15Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

if(!$staticpath)
	$staticpath=dirname(__FILE__) . '/';
$IgnoreFiles=Array(".DS_Store","CVS",'.svn');

// Start Session.
session_start();

require_once($staticpath."config.inc.php");
require_once($staticpath."database.inc.php");
	
// Load functions.
if($handle = opendir($staticpath."functions/")) 
{
	while (false !== ($file = readdir($handle))) 
	{				
		// if filename isn't '.' '..' or in the Ignore list... load it.
		if(preg_match("/.*\.php$/i",$file))
			require_once($staticpath."functions/$file");
	}
}

$language = Preferences('LANGUAGE');
$lang = substr($language,0,2);
if($lang=='ar' || $lang=='ur' || $lang=='fa' || $lang=='he' || $lang=='ku')
{
	$_FOCUS['direction'] = 'RTL';
	define('ALIGN_RIGHT','left');
	define('ALIGN_LEFT','right');
}
else
{
	$_FOCUS['direction'] = '';
	define('ALIGN_RIGHT','right');
	define('ALIGN_LEFT','left');
}

if($language=='en_US' && !function_exists('_'))
{
	function _($text)
	{
		return $text;
	}	
}
elseif(function_exists('gettext'))
{
	$character_set  = 'UTF-8';
	putenv("LANG=$language"); 
	putenv("LANGUAGE=$language"); 
	setlocale(LC_ALL, $language);
	
	$domain = 'messages';
	bindtextdomain($domain,$staticpath.'locale/');
	textdomain($domain);
	bind_textdomain_codeset($domain,$character_set);
}
else
{
	require_once($staticpath.'php-gettext/streams.php');
	require_once($staticpath.'php-gettext/gettext.php');
	
	$file = $staticpath.'locale/'.$language.'/LC_MESSAGES/messages.mo';
	
	if(file_exists($file))
	{
		$input = new FileReader($LangFile);
		$PhpGettext = new gettext_reader($input);
		
		if(!function_exists('_'))
		{
			function _($text)
			{	global $PhpGettext;
				
				return $PhpGettext->translate($text);
			}
		}
	}
	elseif(!function_exists('_'))
	{
		function _($text)
		{
			return $text;
		}
	}
}

if(!$dont_header_for_logout && !$_SESSION['USERNAME'] && !$_SESSION['STUDENT_ID'] && strpos($_SERVER['PHP_SELF'],'index.php')===false)
{
	header('Location: index.php');
	exit;
}

// TAKEN FROM MOODLE
// Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others)
// http://www.google.com/webmasters/faq.html#prefetchblock
if(!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch')
{
	header($_SERVER['SERVER_PROTOCOL'] . ' 404 Prefetch Forbidden');        
	trigger_error('Prefetch request forbidden.');
	exit;
}


function Warehouse($mode)
{	global $__SHOW_FOOTER,$_FOCUS,$menu_divs,$language,$staticpath;

	switch($mode)
	{
		case 'header':
			if($language=='en_US')
				echo "<HTML>";
			else
				echo '<HTML lang="'.substr($language,0,2).'" xml:lang="'.substr($language,0,2).'">';
			echo "<HEAD><TITLE>Focus/SIS Student Information System</TITLE>";
			if($language!='en_US')
				echo '<meta http-equiv="Content-Type" content="text/html; charset="UTF-8" /><meta http-equiv="Content-Language" content="'.strtolower(str_replace('_','-',$language)).'" />';

			if(basename($_SERVER['PHP_SELF'])!='index.php')
				echo "<noscript><META http-equiv=REFRESH content='0;url=index.php?modfunc=logout&reason=javascript' /></noscript>";
			echo "<script language='JavaScript' src='assets/modules.js'></script>";
			// avoid User() if not logged in
			if(Preferences('MENU')=='Top')
				echo '<script language="javascript" src="assets/parents.js"></script>';
			else
				echo '<script language="javascript">function positionMenus() { return; }</script>';
			echo "<script language=\"JavaScript\" type=\"text/javascript\">";
			echo 'var highlightColor = "#'.Preferences('HIGHLIGHT').'";';
			if(basename($_SERVER['PHP_SELF'])=='index.php')
			{
				echo "
						if(parent.frames.length > 0)
						{
							parent.location.href = 'index.php?modfunc=logout';
						}";
			}
			echo "</script>
				<link rel=stylesheet type=text/css href=assets/themes/".Preferences('THEME')."/stylesheet.css>";
			if($_FOCUS['direction']=='RTL')
				echo '<link rel="stylesheet" type="text/css" media="all" href="assets/rtl.css" />';
			if(strpos($_REQUEST['modname'],'Food_Service')!==false)
				echo '<link rel="stylesheet" type="text/css" media="all" href="modules/Food_Service/management/theme/default/css/main.css" />';
			echo '  <link rel="stylesheet" type="text/css" media="all" href="assets/jscalendar/calendar-blue2.css" />
			<script type="text/javascript" src="assets/jscalendar/calendar.js"></script>
			<script type="text/javascript" src="assets/jscalendar/lang/calendar-en.js"></script>
			<script type="text/javascript" src="assets/jscalendar/calendar-setup.js"></script>
			<script type="text/javascript" src="assets/tipmessage/main15.js"></script>';
			echo '</HEAD>';
		break;
		case "footer":
			//echo '</TD></TR></TABLE>';
			echo $menu_divs;

			for($i=1;$i<=$_FOCUS['PrepareDate'];$i++)
			{
				echo '<script type="text/javascript">
			Calendar.setup({
				monthField     :    "monthSelect'.$i.'",
				dayField       :    "daySelect'.$i.'",
				yearField      :    "yearSelect'.$i.'",
				ifFormat       :    "%d-%b-%y",
				button         :    "trigger'.$i.'",
				align          :    "Tl",
				singleClick    :    true
			});
		</script>';
			}
			echo '</BODY>';
			echo '</HTML>';	
		break;
	}
}
?>